package com.hanbang.chu_xing_gao_zhao.view_find_esoterica;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hanbang.chu_xing_gao_zhao.application.HttpInterfaces;
import com.hanbang.chu_xing_gao_zhao.application.MyApplication;
import com.hanbang.chu_xing_gao_zhao.base.BaseDataActivity;
import com.hanbang.chu_xing_gao_zhao.entity.FindEsotericaDataK;
import com.hanbang.chu_xing_gao_zhao.myview.MorePopupWindowPublic_B;
import com.hanbang.chu_xing_gao_zhao.utils.BitmapUtil;
import com.hanbang.chu_xing_gao_zhao.utils.JsonHelper;
import com.hanbang.chu_xing_gao_zhao.utils.MyLog;
import com.hanbang.chu_xing_gao_zhao.utils.MyRequestCallBack;
import com.hanbang.chu_xing_gao_zhao.utils.MySharedPreferences;
import com.hanbang.chu_xing_gao_zhao.utils.MyToast;
import com.hanbang.chu_xing_gao_zhao.utils.SystemTools;
import com.hanbang.chu_xing_gao_zhao.utils.UiUtils;
import com.hanbang.cxgz_2.R;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.client.HttpRequest;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 秘籍展示:
 * 1是开放秘籍
 * 2是买断秘籍
 *
 * @author yang
 */
public class FindEsotericaActivity extends BaseDataActivity implements OnClickListener {


    /**
     * 瀑布流控件
     */
    private RecyclerView mRecyclerView;

    /**
     * 瀑布流数据集合
     */
    private List<FindEsotericaDataK> listData;

    /**
     * 瀑布流适配器
     */
    private MyRecyclerViewAdapterB adapter;


    /**
     * 状态
     * 1是开放秘籍
     * 2是买断秘籍
     */
    private int status = 1;

    /**
     * 页大小
     */
    private int pageSize = 10;

    /**
     * 第几页
     */
    private int pageIndex = 1;

    /**
     * 请求参数
     */
    private RequestParams params;

    /**
     * 菜系id
     */
    private int cuisines_id = -1;
    /**
     * 排序id
     */
    private int sort_id = 1;

    /**
     * 刷新布局
     */
    private SwipeRefreshLayout swipeRefreshLayout;
    /**
     * 旧的集合长度
     */
    int old = -1;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.find_esoterica_activity);

        initView();
        setOnClickListener();
        recyclerAddLinear();
        getHttpList(HttpInterfaces.GetMijiList, params);

        swipeRefreshLayout();

    }


    /**
     * 初始化view
     */
    private void initView() {

        setTitleMore(View.VISIBLE, View.VISIBLE, "开放式秘籍", "买断式秘籍", null, null);
        ((TextView) findViewById(R.id.tv_bar_top_conver_classify_title1)).setBackgroundResource(R.color.white);
        setBackArrows(findViewById(R.id.bar_top_conver_classify_back));

        mRecyclerView = (RecyclerView) this.findViewById(R.id.find_activity_recyclerView);

        mRecyclerView.setItemAnimator(new DefaultItemAnimator());

        swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);

        listData = new ArrayList<FindEsotericaDataK>();
        //页面的初始显示
        params = new RequestParams();
        params.addBodyParameter("telphone", MySharedPreferences.getSharedPreferencesKeyAndValue(
                FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "tlephone"));
        params.addBodyParameter("password", MySharedPreferences.getSharedPreferencesKeyAndValue(
                FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "password"));

        params.addBodyParameter("type", status + "");
        params.addBodyParameter("pageSize", pageSize + "");
        params.addBodyParameter("pageIndex", pageIndex + "");
        params.addBodyParameter("cuisines_id", cuisines_id + "");
        params.addBodyParameter("sort_id", sort_id + "");


    }

    /**
     * recyclerView 添加适配器 与添加监听
     */
    private void recyclerAddLinear() {
        /**
         * 第一个参数，是控件列数或行数，第二参数是控制方向
         *  设置RecyclerView布局管理器为2列垂直排布
         */
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));// 设置RecyclerView布局管理器为2列垂直排布

        adapter = new MyRecyclerViewAdapterB(this, listData);

        mRecyclerView.setAdapter(adapter);

        adapter.setOnClickListener(new OnItemClickListener() {

            //跳转到详情界面
            public void ItemClickListener(View view, int postion) {
//                Toast.makeText(FindEsotericaActivity.this, "点击了：" + postion, Toast.LENGTH_SHORT).show();

                Intent intent = new Intent();
                if (status == 2) {

                    intent.setClass(FindEsotericaActivity.this, FindEsotericaDetails_D.class);
                } else {
                    MyLog.e("text","*************"+listData.get(postion - 1).getPrice());

                    if (listData.get(postion - 1).getPrice() > 0) {
                        intent.setClass(FindEsotericaActivity.this, FindEsotericaDetails_K_PayFront.class);
                        intent.putExtra("price", "收费");
                    } else {
                        intent.setClass(FindEsotericaActivity.this, FindEsotericaDetails_K_PayBack.class);
                        intent.putExtra("price", "免费");
                    }
                }


                intent.putExtra("name", listData.get(postion - 1).getTitle());
                intent.putExtra("id", listData.get(postion - 1).getId());
                startActivity(intent);
            }


            public void ItemLongClickListener(View view, int postion) {
                // 长按删除
//                listData.remove(postion);
//                adapter.notifyItemRemoved(postion);
            }
        });


    }

    /**
     *
     */
    private void swipeRefreshLayout() {

        //刷新布局
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeRefreshLayout.setRefreshing(false);

                listData.clear();
                pageIndex = 1;
                old = -1;

                RequestParams params2 = new RequestParams();
                params2 = new RequestParams();
                params2.addBodyParameter("telphone", MySharedPreferences.getSharedPreferencesKeyAndValue(
                        FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "tlephone"));
                params2.addBodyParameter("password", MySharedPreferences.getSharedPreferencesKeyAndValue(
                        FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "password"));
                params2.addBodyParameter("type", status + "");
                params2.addBodyParameter("pageSize", pageSize + "");
                params2.addBodyParameter("pageIndex", pageIndex + "");
                params2.addBodyParameter("cuisines_id", cuisines_id + "");
                params2.addBodyParameter("sort_id", sort_id + "");
                getHttpList(HttpInterfaces.GetMijiList, params2);

            }
        });


        adapter.notifyDataSetChanged();


    }


    /**
     * 设置点击事件
     */
    private void setOnClickListener() {
        ((TextView) findViewById(R.id.tv_bar_top_conver_classify_title2)).setOnClickListener(this);
        ((TextView) findViewById(R.id.tv_bar_top_conver_classify_title1)).setOnClickListener(this);

    }

    /**
     * 监听处理
     * <p/>
     * //调用接口使得的参数
     * type:类型，1为开放式，2为买断式
     * pageSize：分页大小，可为空
     * pageIndex：当前页码，为空默认1
     * cuisines_id：菜系，可为空
     * sort_id：排序的方式，可为空默认1，综合1，最热2，最新3，支持人数4，价格最高5，价格最低6
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            // 买断式秘籍
            case R.id.tv_bar_top_conver_classify_title2:
                listData.clear();
                pageIndex = 1;
                status = 2;
                cuisines_id = -1;
                sort_id = 1;
                old = -1;
                adapter.notifyDataSetChanged();
                //更改标题颜色
                ((TextView) findViewById(R.id.tv_bar_top_conver_classify_title1)).setBackgroundResource(R.color.yellow);
                ((TextView) findViewById(R.id.tv_bar_top_conver_classify_title2)).setBackgroundResource(R.color.white);

                RequestParams params2 = new RequestParams();
                params2 = new RequestParams();
                params2.addBodyParameter("telphone", MySharedPreferences.getSharedPreferencesKeyAndValue(
                        FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "tlephone"));
                params2.addBodyParameter("password", MySharedPreferences.getSharedPreferencesKeyAndValue(
                        FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "password"));
                params2.addBodyParameter("type", status + "");
                params2.addBodyParameter("pageSize", pageSize + "");
                params2.addBodyParameter("pageIndex", pageIndex + "");
                params2.addBodyParameter("sort_id", 1 + "");

                getHttpList(HttpInterfaces.GetMijiList, params2);

                break;
            // 开放式秘籍
            case R.id.tv_bar_top_conver_classify_title1:
                old = -1;
                listData.clear();
                status = 1;
                pageIndex = 1;
                cuisines_id = -1;
                sort_id = 1;
                adapter.notifyDataSetChanged();
                //更改标题颜色
                ((TextView) findViewById(R.id.tv_bar_top_conver_classify_title1)).setBackgroundResource(R.color.white);
                ((TextView) findViewById(R.id.tv_bar_top_conver_classify_title2)).setBackgroundResource(R.color.yellow);

                RequestParams params1 = new RequestParams();
                params1 = new RequestParams();
                params1.addBodyParameter("telphone", MySharedPreferences.getSharedPreferencesKeyAndValue(
                        FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "tlephone"));
                params1.addBodyParameter("password", MySharedPreferences.getSharedPreferencesKeyAndValue(
                        FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "password"));
                params1.addBodyParameter("type", status + "");
                params1.addBodyParameter("pageSize", pageSize + "");
                params1.addBodyParameter("pageIndex", pageIndex + "");
                params1.addBodyParameter("cuisines_id", cuisines_id + "");
                params1.addBodyParameter("sort_id", sort_id + "");

                getHttpList(HttpInterfaces.GetMijiList, params1);
                break;

            default:

                break;
        }


    }

    /**
     * 更改标题显示
     */
    @Override
    protected void onResume() {

        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * 获取秘籍列表
     */
    private void getHttpList(String url, RequestParams params) {
        httpUtils.send(HttpRequest.HttpMethod.POST, url, params, new MyRequestCallBack<String>(this, "加载中...") {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                super.onSuccess(responseInfo);
                try {
                    JSONObject json = new JSONObject(responseInfo.result);
                    int result = json.getInt("Result");
                    if (result == 0) {
                        JSONArray jsonArray = json.getJSONArray("list");
                        if (jsonArray.length() == 0) {
                            MyToast.show(FindEsotericaActivity.this, "没有更多内容", 1);
                            adapter.notifyDataSetChanged();
                            return;
                        }

                        // 把数据从接口解析出来
                        listData.addAll(JsonHelper.parseCollection(jsonArray, ArrayList.class, FindEsotericaDataK.class));

//                        MyLog.i("text", "555*****" + listData.toString());

                        adapter.notifyDataSetChanged();

                    } else {
                        MyToast.show(FindEsotericaActivity.this, "服务器忙，请稍后重试..", 1);

                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 适配器
     */
    public class MyRecyclerViewAdapterB extends RecyclerView.Adapter<MyViewHolderB> implements View.OnClickListener {
        /**
         * 数据
         */
        private List<FindEsotericaDataK> lists;
        private Context context;
        private OnItemClickListener mListener;

        BitmapUtils bitmapUtils;

        /**
         * 中部导航按钮-菜系
         */
        private LinearLayout styleOfCooking;

        /**
         * 中部导航按钮-最热
         */
        private LinearLayout hottest;

        /**
         * 上传秘籍
         */
        private LinearLayout uploading;


        /**
         * 加载
         */
        private TextView loading;

        // view的type：头部，内容，加载更多
        private static final int TYPE_HEADER = 1, TYPE_ITEM = 2, LOADING = 3;


        public MyRecyclerViewAdapterB(Context context, List<FindEsotericaDataK> lists) {
            this.context = context;


            bitmapUtils = BitmapUtil.getBitmapUtils(context, MyApplication.bitmapCachePath);

            if (lists != null) {
                this.lists = lists;

            } else {
                this.lists = new ArrayList<FindEsotericaDataK>();
            }

        }


        @Override
        public void onClick(View v) {

            Intent intent = new Intent();
            MorePopupWindowPublic_B popup = null;
//            MorePopupWindowPublic hottestPopup = null;
            switch (v.getId()) {

                // 菜系
                case R.id.ll_bar_mid_conver_gang_styleOfCooking:

                    popup = new MorePopupWindowPublic_B(context, styleOfCookingList, 8, 100);

                    popup.showPopupWindow(styleOfCooking.getChildAt(0), 2);
                    break;
                // 筛选
                case R.id.ll_bar_mid_conver_classify_hottest:

                    if (status == 1) {
                        popup = new MorePopupWindowPublic_B(context, sortId_kf, 8, 200);
                        popup.showPopupWindow(hottest.getChildAt(0), 2);
                    }
                    if (status == 2) {
                        popup = new MorePopupWindowPublic_B(context, sortId_md, 8, 200);
                        popup.showPopupWindow(hottest.getChildAt(0), 2);
                    }


                    break;

                // 上传秘籍
                case R.id.ll_find_esoterica_uploading:

                    if (status == 1) {
                        intent.setClass(context, FindEsotericaUploadingActivityK.class);
                        context.startActivity(intent);

                    } else {
                        intent.setClass(context, FindEsotericaUploadingActivityD.class);
                        context.startActivity(intent);
                    }
                    break;

                //加载更多
                case R.id.tv_list_foot_loading:
                    ++pageIndex;
                    RequestParams params4 = new RequestParams();
                    params4 = new RequestParams();
                    params4.addBodyParameter("telphone", MySharedPreferences.getSharedPreferencesKeyAndValue(
                            FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "tlephone"));
                    params4.addBodyParameter("password", MySharedPreferences.getSharedPreferencesKeyAndValue(
                            FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "password"));
                    params4.addBodyParameter("type", status + "");
                    params4.addBodyParameter("pageSize", pageSize + "");
                    params4.addBodyParameter("pageIndex", pageIndex + "");
                    params4.addBodyParameter("cuisines_id", cuisines_id + "");
                    params4.addBodyParameter("sort_id", sort_id + "");

                    getHttpList(HttpInterfaces.GetMijiList, params4);
                    old = lists.size();


                default:

                    break;
            }
            // 菜系点击监听的处理
            if (popup != null) {


                popup.setOnClickCallback(new MorePopupWindowPublic_B.OnClickCallback() {
                    @Override
                    public void onClick(MorePopupWindowPublic_B morePopWindow, int id, String content, int type) {
                        if (type == 100) {
                            listData.clear();
                            pageIndex = 1;
                            cuisines_id = id;

                            MyLog.i("text", "cuisines_id" + id + "");
                            Toast.makeText(FindEsotericaActivity.this, content, Toast.LENGTH_SHORT).show();
                            ((TextView) styleOfCooking.getChildAt(0)).setText(content);

                            RequestParams params3 = new RequestParams();
                            params3 = new RequestParams();
                            params3.addBodyParameter("telphone", MySharedPreferences.getSharedPreferencesKeyAndValue(
                                    FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "tlephone"));
                            params3.addBodyParameter("password", MySharedPreferences.getSharedPreferencesKeyAndValue(
                                    FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "password"));
                            params3.addBodyParameter("type", status + "");
                            params3.addBodyParameter("pageSize", pageSize + "");
                            params3.addBodyParameter("pageIndex", pageIndex + "");
                            params3.addBodyParameter("cuisines_id", cuisines_id + "");
                            params3.addBodyParameter("sort_id", sort_id + "");
                            getHttpList(HttpInterfaces.GetMijiList, params3);
                        }


                        if (type == 200) {
                            listData.clear();
                            pageIndex = 1;
                            sort_id = id;

                            MyLog.i("text", "sort_id" + id + "");

                            Toast.makeText(FindEsotericaActivity.this, content, Toast.LENGTH_SHORT).show();

                            ((TextView) hottest.getChildAt(0)).setText(content);

                            RequestParams params1 = new RequestParams();
                            params1 = new RequestParams();
                            params1.addBodyParameter("telphone", MySharedPreferences.getSharedPreferencesKeyAndValue(
                                    FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "tlephone"));
                            params1.addBodyParameter("password", MySharedPreferences.getSharedPreferencesKeyAndValue(
                                    FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "password"));
                            params1.addBodyParameter("type", status + "");
                            params1.addBodyParameter("pageSize", pageSize + "");
                            params1.addBodyParameter("pageIndex", pageIndex + "");
                            params1.addBodyParameter("cuisines_id", cuisines_id + "");
                            params1.addBodyParameter("sort_id", 1 + "");
                            getHttpList(HttpInterfaces.GetMijiList, params1);
                        }

                    }
                });


            }


        }

        public void setOnClickListener(OnItemClickListener listener) {
            this.mListener = listener;
        }

        @Override
        public MyViewHolderB onCreateViewHolder(ViewGroup parent, int viewType) {
//            MyLog.i("text", "AAA onCreateViewHolder*****" );
            View view = null;
            // 根据类型填充不同布局
            switch (viewType) {
                //添加头部
                case TYPE_HEADER:
                    view = LayoutInflater.from(context).inflate(R.layout.find_activity_head, parent, false);

                    // 中部多余按钮隐藏
                    ((LinearLayout) view.findViewById(R.id.ll_bar_mid_conver_classify_city)).setVisibility(View.GONE);
                    ((LinearLayout) view.findViewById(R.id.ll_bar_mid_conver_gang_position)).setVisibility(View.GONE);
                    ((LinearLayout) view.findViewById(R.id.bar_mid_age)).setVisibility(View.GONE);
                    ((ImageView) view.findViewById(R.id.im_bar_top_conver_classify_search1)).setVisibility(View.GONE);
                    ((LinearLayout) view.findViewById(R.id.bar_mid_conver_classify_parent)).setBackgroundResource(R.color.gray_ee);
                    uploading = (LinearLayout) view.findViewById(R.id.ll_find_esoterica_uploading);

                    // 控件初始化
                    styleOfCooking = (LinearLayout) view.findViewById(R.id.ll_bar_mid_conver_gang_styleOfCooking);
                    hottest = (LinearLayout) view.findViewById(R.id.ll_bar_mid_conver_classify_hottest);

                    //设置下拉菜单的初始值
                    ((TextView) hottest.getChildAt(0)).setText("综合");
                    ((TextView) styleOfCooking.getChildAt(0)).setText("全部");

                    //添加监听
                    styleOfCooking.setOnClickListener(this);
                    hottest.setOnClickListener(this);
                    uploading.setOnClickListener(this);

                    break;
                //内容
                case TYPE_ITEM:
                    view = LayoutInflater.from(context).inflate(R.layout.item_find_esoterica_k, parent, false);
                    break;
                //加载更多
                case LOADING:

                    view = LayoutInflater.from(context).inflate(R.layout.list_foot_loading, parent, false);
                    loading = (TextView) view.findViewById(R.id.tv_list_foot_loading);
                    loading.setOnClickListener(this);

            }

            //更改字体
            UiUtils.applyFont(view);
            MyViewHolderB viewHolder = new MyViewHolderB(view);
            return viewHolder;
        }


        @Override
        public void onBindViewHolder(final MyViewHolderB holder, int position) {
            switch (holder.getItemViewType()) {
                //使用头单独占一行
                case TYPE_HEADER:
                    // 最最关键一步，设置当前view占满列数，这样就可以占据两列实现头部了
                    StaggeredGridLayoutManager.LayoutParams clp = (StaggeredGridLayoutManager.LayoutParams) holder.head.getLayoutParams();
                    /**
                     * 如果设置为true，该项目将布局采用全量程范围。这意味着，如果方向
                      *是垂直的，认为将有充分的宽度;如果方向是水平的，视图将
                      *有充分的高度。
                       *参数fullSpan如果此项目应遍历所有的跨度。
                     */
                    clp.setFullSpan(true);

                    break;
                //内容的展示
                case TYPE_ITEM:
                    if (lists.size() == 0 || lists.size() < position) {
                        return;
                    }
                    //因为传过来的position是从0开始，所以要减1.
                    position = position - 1;
                    ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();// 得到item的LayoutParams布局参数
                    holder.itemView.setLayoutParams(params);// 把params设置给item布局

//                    MyLog.i("text", "CCC lists.size*****" + lists.size() + "position" + position);
                    bitmapUtils.configDefaultLoadFailedImage(R.drawable.default_white);
                    bitmapUtils.display(holder.picture, SystemTools.getHttpFileUrl(lists.get(position).getImg_url()));


                    holder.craft.setText(lists.get(position).getTitle());
                    holder.price.setText("¥" + String.valueOf(lists.get(position).getPrice()));
                    holder.browse.setText("菜品特色:" + lists.get(position).getTedian());
                    holder.feature.setText("销量：" + lists.get(position).getBuycount());
                    holder.pingFen.setText("评分：" + lists.get(position).getPingfen());


                    //设置item 的监听
                    if (mListener != null) {// 如果设置了监听那么它就不为空，然后回调相应的方法
                        /**
                         * 点击监听
                         */
                        holder.itemView.setOnClickListener(new View.OnClickListener() {

                            public void onClick(View v) {
                                int pos = holder.getPosition();// 得到当前点击item的位置pos
                                mListener.ItemClickListener(holder.itemView, pos);// 把事件交给我们实现的接口那里处理
                            }
                        });
                        /**
                         * 长按监听
                         */
                        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                            @Override
                            public boolean onLongClick(View v) {
                                int pos = holder.getPosition();// 得到当前点击item的位置pos
                                mListener.ItemLongClickListener(holder.itemView, pos);// 把事件交给我们实现的接口那里处理
                                return true;
                            }
                        });
                    }


                    break;
                //使用尾部独占一行
                case LOADING:

                    //如果没有新的数据则隐藏加载按键
                    if (lists.size() == old) {

                        holder.bottom.setVisibility(View.GONE);

                        return;
                    } else {
                        holder.bottom.setVisibility(View.VISIBLE);
                    }

                    //加载尾部布局
                    StaggeredGridLayoutManager.LayoutParams clp1 = (StaggeredGridLayoutManager.LayoutParams) holder.bottom.getLayoutParams();

                    clp1.setFullSpan(true);

//                    MyLog.i("text", "BBB*****" + lists.size() + "old" + old);

                    //自动加载
                    MyLog.i("text", "CCC lists.size*****" + lists.size() + "position" + position);
                    if (position - 1 == listData.size()) {

                        if (old == lists.size()) {
                            return;
                        }

                        ++pageIndex;
                        RequestParams params4 = new RequestParams();
                        params4 = new RequestParams();
                        params4.addBodyParameter("telphone", MySharedPreferences.getSharedPreferencesKeyAndValue(
                                FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "tlephone"));
                        params4.addBodyParameter("password", MySharedPreferences.getSharedPreferencesKeyAndValue(
                                FindEsotericaActivity.this, MySharedPreferences.USER_DATA, "password"));
                        params4.addBodyParameter("type", status + "");
                        params4.addBodyParameter("pageSize", pageSize + "");
                        params4.addBodyParameter("pageIndex", pageIndex + "");
                        params4.addBodyParameter("cuisines_id", cuisines_id + "");
                        params4.addBodyParameter("sort_id", sort_id + "");

                        getHttpList(HttpInterfaces.GetMijiList, params4);
                        old = lists.size();

                    }


                    break;
            }
        }

        @Override
        public int getItemCount() {
            return lists.size() + 2;
        }

        @Override
        public int getItemViewType(int position) {
            //添加一个底部加载使用
            if (position == lists.size() + 1 && lists.size() > 1) {
                return LOADING;
            }
            // 位置为0的话类型为头部，其余为内容
            return position = position == 0 ? TYPE_HEADER : TYPE_ITEM;
        }
    }


    /**
     * 内容控件的初始化
     */
    class MyViewHolderB extends RecyclerView.ViewHolder implements OnClickListener {
        public ImageView picture;
        public TextView craft;
        public TextView price;
        public TextView pingFen;
        public TextView browse;
        public TextView feature;

        public LinearLayout head;
        public LinearLayout bottom;


        public MyViewHolderB(View itemView) {
            super(itemView);
            //头部
            if (itemView.getId() == R.id.ll_find_activity_head) {
                head = (LinearLayout) itemView.findViewById(R.id.ll_find_activity_head);

                //尾部
            } else if (itemView.getId() == R.id.ll_list_foot_loading_parent) {

                bottom = (LinearLayout) itemView.findViewById(R.id.ll_list_foot_loading_parent);
                bottom.setOnClickListener(this);
                //内容
            } else {
                picture = (ImageView) itemView.findViewById(R.id.im_item_find_esoterica_picture);
                craft = (TextView) itemView.findViewById(R.id.tv_item_find_activity_recyclerView_craft);
                pingFen = (TextView) itemView.findViewById(R.id.tv_item_find_activity_recyclerView_pingFen);
                price = (TextView) itemView.findViewById(R.id.tv_item_find_activity_recyclerView_price);
                browse = (TextView) itemView.findViewById(R.id.tv_item_find_activity_recyclerView_browse);
                feature = (TextView) itemView.findViewById(R.id.tv_item_find_activity_recyclerView_feature);
            }
        }

        @Override
        public void onClick(View v) {

        }
    }


    /**
     * 定义回调接口
     */
    interface OnItemClickListener {
        void ItemClickListener(View view, int postion);

        void ItemLongClickListener(View view, int postion);
    }

}


